package com.mgg.auth.service.user.impl;

import com.mgg.auth.service.user.UserService;
import com.mgg.common.util.UUIDUtils;
import com.mgg.common.vo.UserVO;
import com.mgg.common.dao.DaoSupport;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: lijun
 * @Date: 2018/9/7 15:12
 */
@Service("userService")
public class UserServiceImpl implements UserService{

    @Autowired
    private DaoSupport dao;

    @Override
    public UserVO getUserByPhone(String phone) {
        UserVO user = dao.findForObject("UserMapper.getUserByPhone", phone);
        return user;
    }

    @Override
    public UserVO getUserByUserId(String userId) {
        UserVO user = dao.findForObject("UserMapper.getUserByUserId", userId);
        return user;
    }

    @Override
    public String saveProviderUser(String username, String headImg) {
        Map<String,Object> userMap = new HashMap<>();
        //插入用户信息表
        String userId = UUIDUtils.get32UUID();
        userMap.put("userId",userId);
        userMap.put("userStatus", "1");
        dao.findForObject("UserMapper.insertUser", userMap);

        //插入用户账户表
        userMap.put("total_income", 0);
        userMap.put("amount", 0);
        userMap.put("pre_amount", 0);
        dao.findForObject("UserMapper.insertUserAccount", userMap);
        return userId;
    }
}
